// array 的应用
// Created by FanGccU on 2025/6/22.
// 固定数组，运行时不能修改大小
// 性能要比 vector 高


#include <array>
#include <iostream>
using namespace std;

array<int, 5> arr1 = {1, 2, 3, 4, 5};
array<int, 5> arr2 = {5, 4, 3, 2, 1};

int main(int argc, char *argv[]) {
    cout << "arr values：";
    for (const auto value: arr1) {
        cout << value << "\t";
    }
    cout << endl;

    cout << "第一个元素为：" << arr1.front() << endl;
    cout << "最后一个元素为：" << arr1.back() << endl;

    arr1.swap(arr2);

    cout << "交换后arr1的数据：";
    for (int i = 0; i < arr1.size(); i++) {
        cout << arr1.at(i) << "\t";
    }
    cout << endl;

    cout << "交换后arr2的数据：";
    for (int i : arr2) {
        cout << i << "\t";
    }
    cout << endl;
}
